 package handling.channel.handler;



import client.MapleCharacter;
import client.MapleClient;
import client.MapleQuestStatus;
import client.RockPaperScissors;
import client.inventory.Equip;
import client.inventory.Item;
import client.inventory.ItemFlag;
import client.inventory.MapleInventoryType;
import configs.ServerConfig;
import constants.GameConstants;
import constants.ItemConstants;
import handling.channel.ChannelServer;
import handling.opcode.EffectOpcode;
import handling.opcode.NPCTalkOP;
import handling.opcode.SendPacketOpcode;
import handling.world.WorldBroadcastService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import scripting.item.ItemScriptManager;
import scripting.npc.NPCScriptManager;
import scripting.quest.QuestScriptManager;
import server.AutobanManager;
import server.MapleInventoryManipulator;
import server.MapleItemInformationProvider;
import server.MapleStorage;
import server.life.MapleNPC;
import server.maps.MapleMap;
import server.maps.MapleQuickMove;
import server.quest.MapleQuest;
import server.shop.MapleShop;
import tools.MaplePacketCreator;
import tools.Pair;
import tools.data.input.LittleEndianAccessor;
import tools.data.output.MaplePacketLittleEndianWriter;
import tools.packet.EffectPacket;
import tools.packet.NPCPacket;

import java.util.HashMap;
import java.util.Map;















































 public class NPCHandler
 {
/*  52 */   private static final Logger log = LogManager.getLogger(NPCHandler.class);
/*  53 */   private static final Logger log_storage = LogManager.getLogger("StorageLog");












   public static void NPCAnimation(LittleEndianAccessor slea, MapleClient c) {
/*  67 */     MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();
/*  68 */     mplew.writeShort(SendPacketOpcode.NPC_ACTION.getValue());
/*  69 */     int length = (int)slea.available();
/*  70 */     int npcOid = slea.readInt();
/*  71 */     byte type1 = slea.readByte();
/*  72 */     byte type2 = slea.readByte();
/*  73 */     mplew.writeInt(npcOid);
/*  74 */     mplew.write(type1);
/*  75 */     mplew.write(type2);
/*  76 */     if (length == 10) {
/*  77 */       mplew.writeInt(slea.readInt());
/*  78 */     } else if (length > 6) {
/*  79 */       mplew.write(slea.read(length - 6));
     } else {
       return;
     }
/*  83 */     if (type2 == 1) {
/*  84 */       c.announce(NPCPacket.moveNpc(mplew));
       return;
     }
/*  87 */     c.announce(mplew.getPacket());
   }

   public static void NPCShop(LittleEndianAccessor slea, MapleClient c, MapleCharacter chr) {
     short position, slot;
     int itemId;
     short quantity;
/*  94 */     byte bmode = slea.readByte();
/*  95 */     if (chr == null) {
       return;
     }
/*  98 */     MapleShop shop = chr.getShop();
/*  99 */     if (shop == null) {
       return;
     }
/* 102 */     switch (bmode) {
       case 0:
/* 104 */         position = slea.readShort();
/* 105 */         itemId = slea.readInt();
/* 106 */         quantity = slea.readShort();
/* 107 */         shop.buy(c, itemId, quantity, position);
         return;

       case 1:
/* 111 */         slot = slea.readShort();
/* 112 */         itemId = slea.readInt();
/* 113 */         quantity = slea.readShort();
/* 114 */         shop.sell(c, ItemConstants.getInventoryType(itemId), slot, quantity);
         return;

       case 2:
/* 118 */         slot = slea.readShort();
/* 119 */         shop.recharge(c, slot);
         return;
     }

/* 123 */     chr.setConversation(0);
   }






   public static void NPCTalk(LittleEndianAccessor slea, MapleClient c, MapleCharacter chr) {
/* 132 */     if (chr == null || chr.getMap() == null || chr.getBattle() != null || !c.canClickNPC()) {
/* 133 */       c.announce(MaplePacketCreator.enableActions());
       return;
     }
/* 136 */     MapleNPC npc = chr.getMap().getNPCByOid(slea.readInt());
/* 137 */     if (npc == null) {
       return;
     }
/* 140 */     if (chr.hasBlockedInventory()) {
/* 141 */       c.announce(MaplePacketCreator.enableActions());
       return;
     }
/* 144 */     if (chr.getAntiMacro().inProgress()) {
/* 145 */       chr.dropMessage(5, "被使用测谎仪时无法操作。");
/* 146 */       c.announce(MaplePacketCreator.enableActions());
       return;
     }
/* 149 */     chr.setCurrenttime(System.currentTimeMillis());
/* 150 */     if (chr.getCurrenttime() - chr.getLasttime() < chr.getDeadtime()) {
/* 151 */       if (chr.isGM()) {
/* 152 */         chr.dropMessage(5, "连接速度过快，请稍后再试。");
       }

/* 155 */       c.announce(MaplePacketCreator.enableActions());
       return;
     }
/* 158 */     chr.setLasttime(System.currentTimeMillis());

/* 160 */     if (npc.hasShop()) {
/* 161 */       chr.setConversation(1);
/* 162 */       npc.sendShop(c);
     } else {
/* 164 */       NPCScriptManager.getInstance().start(c, npc.getId());
     }
   }



   public static void QuestAction(LittleEndianAccessor slea, MapleClient c, MapleCharacter chr) {
     int itemid, npc;
/* 172 */     byte action = slea.readByte();
/* 173 */     int quest = slea.readInt();

/* 175 */     if (chr == null) {
       return;
     }
/* 178 */     if (chr.hasBlockedInventory()) {
/* 179 */       chr.sendEnableActions();

       return;
     }
/* 183 */     if (chr.getAntiMacro().inProgress()) {
/* 184 */       chr.dropMessage(5, "被使用测谎仪时无法操作。");
/* 185 */       c.announce(MaplePacketCreator.enableActions());

       return;
     }
/* 189 */     boolean autoFinal = false;
/* 190 */     switch (quest) {
       case 1430:
       case 1434:
       case 1438:
       case 1441:
       case 1444:
/* 196 */         autoFinal = true;
         break;
     }


/* 201 */     if (autoFinal && c.getPlayer().getQuestStatus(quest) != 1 && c.getPlayer().getMapId() != 211000001) {
/* 202 */       MapleMap toMap = ChannelServer.getInstance(c.getChannel()).getMapFactory().getMap(211000001);
/* 203 */       c.getPlayer().changeMap(toMap, toMap.getPortal(0));
     }

/* 206 */     MapleQuest q = MapleQuest.getInstance(quest);
/* 207 */     switch (action) {
       case 0:
/* 209 */         slea.readInt();
/* 210 */         itemid = slea.readInt();
/* 211 */         q.RestoreLostItem(chr, itemid);
         break;

       case 1:
/* 215 */         npc = slea.readInt();
/* 216 */         if (!q.hasStartScript()) {

/* 218 */           if (chr.isAdmin() && ServerConfig.WORLD_SHOWQUESTINFO) {
/* 219 */             chr.dropMessage(6, "开始系统任务 NPC: " + npc + " Quest：" + quest);
           }

/* 222 */           q.start(chr, npc);
         }
         break;

       case 2:
/* 227 */         npc = slea.readInt();
/* 228 */         slea.readInt();
/* 229 */         if (q.hasEndScript()) {
           return;
         }
/* 232 */         if (slea.available() >= 4L) {
/* 233 */           q.complete(chr, npc, Integer.valueOf(slea.readInt()));
         } else {
/* 235 */           q.complete(chr, npc);
         }
/* 237 */         if (chr.isAdmin() && ServerConfig.WORLD_SHOWQUESTINFO) {
/* 238 */           chr.dropMessage(6, "完成系统任务 NPC: " + npc + " Quest: " + quest);
         }
         break;







       case 3:
/* 249 */         if (GameConstants.canForfeit(q.getId())) {
/* 250 */           q.forfeit(chr);
/* 251 */           if (chr.isAdmin() && ServerConfig.WORLD_SHOWQUESTINFO)
/* 252 */             chr.dropMessage(6, "放弃系统任务 Quest: " + quest); 
           break;
         }
/* 255 */         chr.dropMessage(1, "无法放弃这个任务.");
         break;


       case 4:
/* 260 */         npc = slea.readInt();
/* 261 */         if (chr.hasBlockedInventory()) {
/* 262 */           c.announce(MaplePacketCreator.enableActions());
           return;
         }
/* 265 */         if (chr.isAdmin() && ServerConfig.WORLD_SHOWQUESTINFO) {
/* 266 */           chr.dropMessage(6, "执行脚本任务 NPC：" + npc + " Quest: " + quest);
         }
/* 268 */         QuestScriptManager.getInstance().startQuest(c, npc, quest);
         break;

       case 5:
/* 272 */         npc = slea.readInt();
/* 273 */         if (chr.hasBlockedInventory()) {
/* 274 */           c.announce(MaplePacketCreator.enableActions());
           return;
         }
/* 277 */         QuestScriptManager.getInstance().endQuest(c, npc, quest, false);
/* 278 */         if (chr.isAdmin() && ServerConfig.WORLD_SHOWQUESTINFO) {
/* 279 */           chr.dropMessage(6, "完成脚本任务 NPC：" + npc + " Quest: " + quest);
         }
         break;

       case 6:
/* 284 */         if (chr.isAdmin() && ServerConfig.WORLD_SHOWQUESTINFO) {
/* 285 */           chr.dropMessage(6, "完成脚本任务 Quest: " + quest);
         }
/* 287 */         chr.send(EffectPacket.showSpecialEffect(EffectOpcode.UserEffect_QuestComplete.getValue()));
/* 288 */         chr.getMap().broadcastMessage(chr, EffectPacket.showForeignEffect(chr.getId(), EffectOpcode.UserEffect_QuestComplete.getValue()), false); break;
     }  } public static void Storage(LittleEndianAccessor slea, MapleClient c, MapleCharacter chr) { byte type; short slot; long meso; byte b1; int itemId;
     short quantity;
     long storageMesos;
     Item item;
     MapleInventoryType mapleInventoryType;
     int i;
     long playerMesos;
     Item item1;
/* 297 */     byte mode = slea.readByte();
/* 298 */     if (chr == null) {
       return;
     }
/* 301 */     if (chr.getAntiMacro().inProgress()) {
/* 302 */       chr.dropMessage(5, "被使用测谎仪时无法操作。");
/* 303 */       c.announce(MaplePacketCreator.enableActions());
       return;
     }
/* 306 */     MapleStorage storage = chr.getStorage();
/* 307 */     MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
/* 308 */     switch (mode) {
       case 4:
/* 310 */         type = slea.readByte();
/* 311 */         b1 = slea.readByte();
/* 312 */         quantity = slea.readShort();
/* 313 */         b1 = storage.getSlot(MapleInventoryType.getByType(type), b1);
/* 314 */         item = storage.getItem((short)b1);
/* 315 */         if (item != null) {

/* 317 */           if (ii.isPickupRestricted(item.getItemId()) && chr.getItemQuantity(item.getItemId(), true) > 0) {
/* 318 */             c.announce(NPCPacket.getStorageError((byte)12));

             return;
           }
/* 322 */           int j = (storage.getNpcId() == 9030100 || storage.getNpcId() == 9031016) ? 1000 : 0;
/* 323 */           if (chr.getMeso() < j) {
/* 324 */             c.announce(NPCPacket.getStorageError((byte)11));

             return;
           }
/* 328 */           if (MapleInventoryManipulator.checkSpace(c, item.getItemId(), item.getQuantity(), item.getOwner())) {
/* 329 */             item = storage.takeOut((short)b1);
/* 330 */             short flag = item.getFlag();
/* 331 */             if (ItemFlag.可以交换1次.check(flag)) {
/* 332 */               item.setFlag((short)(flag - ItemFlag.可以交换1次.getValue()));
/* 333 */             } else if (ItemFlag.宿命剪刀.check(flag)) {
/* 334 */               item.setFlag((short)(flag - ItemFlag.宿命剪刀.getValue()));
/* 335 */             } else if (ItemFlag.转存吊牌.check(flag)) {
/* 336 */               item.setFlag((short)(flag - ItemFlag.转存吊牌.getValue()));
/* 337 */             } else if (ItemFlag.宿命剪刀.check(flag)) {
/* 338 */               item.setFlag((short)(flag - ItemFlag.宿命剪刀.getValue()));
             }
/* 340 */             MapleInventoryManipulator.addFromDrop(c, item, false);
/* 341 */             if (j > 0) {
/* 342 */               chr.gainMeso(-j, false);
             }

/* 345 */             log_storage.info("[仓库取出] " + c.getPlayer().getName() + " 道具:" + item.getItemId() + "-" + ii.getName(item.getItemId()) + " 数量:" + item.getQuantity() + " 地图:" + c.getPlayer().getMapId());

/* 347 */             storage.sendTakenOut(c, ItemConstants.getInventoryType(item.getItemId()));
           } else {
/* 349 */             c.announce(NPCPacket.getStorageError((byte)10));
           }
         } else {

/* 353 */           log.info("[作弊] " + chr.getName() + " (等级 " + chr.getLevel() + ") 试图从仓库取出不存在的道具.");
/* 354 */           WorldBroadcastService.getInstance().broadcastGMMessage(MaplePacketCreator.serverNotice(6, "[GM消息] 玩家: " + chr.getName() + " (等级 " + chr.getLevel() + ") 试图从仓库取出不存在的道具."));
/* 355 */           c.announce(MaplePacketCreator.enableActions());
         }
         return;

       case 5:
/* 360 */         slot = slea.readShort();
/* 361 */         itemId = slea.readInt();
/* 362 */         quantity = slea.readShort();

/* 364 */         if (quantity < 1) {
/* 365 */           AutobanManager.getInstance().autoban(c, "试图存入到仓库的道具数量: " + quantity + " 道具ID: " + itemId);

           return;
         }
/* 369 */         if (storage.isFull()) {
/* 370 */           c.announce(NPCPacket.getStorageError((byte)17));

           return;
         }
/* 374 */         mapleInventoryType = ItemConstants.getInventoryType(itemId);
/* 375 */         if (chr.getInventory(mapleInventoryType).getItem(slot) == null) {
/* 376 */           c.announce(MaplePacketCreator.enableActions());

           return;
         }
/* 380 */         i = (storage.getNpcId() == 9030100 || storage.getNpcId() == 9031016) ? 500 : 100;
/* 381 */         if (chr.getMeso() < i) {
/* 382 */           c.announce(NPCPacket.getStorageError((byte)16));

           return;
         }
/* 386 */         item1 = chr.getInventory(mapleInventoryType).getItem(slot).copy();


/* 389 */         if (ii.isDropRestricted(item1.getItemId())) {
/* 390 */           short flag = item1.getFlag();
/* 391 */           if (!ItemFlag.可以交换1次.check(flag) && !ItemFlag.宿命剪刀.check(flag)) {
/* 392 */             chr.ban("客户端道具属性与服务端不匹配 道具ID:" + itemId + " 数量: " + quantity, false, true, false);

             return;
           }
         }

/* 398 */         if (ItemConstants.isPet(item1.getItemId())) {
/* 399 */           c.announce(MaplePacketCreator.enableActions());

           return;
         }
/* 403 */         if (ii.isPickupRestricted(item1.getItemId()) && storage.findById(item1.getItemId()) != null) {
/* 404 */           c.announce(MaplePacketCreator.enableActions());
           return;
         }
/* 407 */         if (item1.getItemId() == itemId && (item1.getQuantity() >= quantity || ItemConstants.isRechargable(itemId))) {

/* 409 */           if (ItemConstants.isRechargable(itemId)) {
/* 410 */             quantity = item1.getQuantity();
           }
/* 412 */           MapleInventoryManipulator.removeFromSlot(c, mapleInventoryType, slot, quantity, false);
/* 413 */           chr.gainMeso(-i, false, false);
/* 414 */           item1.setQuantity(quantity);
/* 415 */           storage.store(item1);

/* 417 */           log_storage.info("[仓库存入] " + c.getPlayer().getName() + " 道具:" + item1.getItemId() + "-" + ii.getName(item1.getItemId()) + " 数量:" + item1.getQuantity() + " 地图:" + c.getPlayer().getMapId());

/* 419 */           storage.sendStored(c, ItemConstants.getInventoryType(itemId));
         } else {
/* 421 */           AutobanManager.getInstance().addPoints(c, 1000, 0L, "试图存入到仓库的道具: " + itemId + " 数量: " + quantity + " 当前玩家用道具: " + item1.getItemId() + " 数量: " + item1.getQuantity());
         }
         return;

       case 6:
/* 426 */         storage.arrange();
/* 427 */         storage.update(c);
         return;

       case 7:
/* 431 */         meso = slea.readLong();
/* 432 */         storageMesos = storage.getMeso();
/* 433 */         playerMesos = chr.getMeso();
/* 434 */         if ((meso > 0L && storageMesos >= meso) || (meso < 0L && playerMesos >= -meso)) {
/* 435 */           if (meso < 0L && storageMesos - meso < 0L) {
/* 436 */             meso = (int)-(ServerConfig.CHANNEL_PLAYER_MAXMESO - storageMesos);
/* 437 */             if (-meso > playerMesos) {
               return;
             }
/* 440 */           } else if (meso > 0L && playerMesos + meso < 0L) {
/* 441 */             meso = (int)(ServerConfig.CHANNEL_PLAYER_MAXMESO - playerMesos);
/* 442 */             if (meso > storageMesos) {
               return;
             }
           }
/* 446 */           if (meso > 0L && chr.getMeso() + meso > ServerConfig.CHANNEL_PLAYER_MAXMESO) {
/* 447 */             chr.dropMessage(1, "玩家身上装备不能超过100E。");
/* 448 */             c.announce(NPCPacket.getStorageError((byte)23));
             return;
           }
/* 451 */           storage.setMeso(storageMesos - meso);
/* 452 */           chr.gainMeso(meso, false, false);
         } else {
/* 454 */           AutobanManager.getInstance().addPoints(c, 1000, 0L, "Trying to store or take out unavailable amount of mesos (" + meso + "/" + storage.getMeso() + "/" + c.getPlayer().getMeso() + ")");
           return;
         }
/* 457 */         storage.sendMeso(c);
         return;

       case 8:
/* 461 */         storage.close();
/* 462 */         chr.setConversation(0);
         return;
     }

/* 466 */     System.out.println("Unhandled Storage mode : " + mode); }

























































































public static void NPCMoreTalk(LittleEndianAccessor slea, MapleClient c) {
    MapleCharacter player = c.getPlayer();
    if (player == null) {
        return;
    }
    if (player.getConversation() != 1) {
        return;
    }
    byte lastMsg = slea.readByte(); // 00 last message type (2 = yesno, 0F = acceptdecline)
    NPCTalkOP op = NPCTalkOP.Companion.getNPCTalkOP(lastMsg);
    if (op == null) {
        c.getPlayer().dropMessage(1, "未知的NPC操作类型:" + lastMsg);
        return;
    }
    if (op == NPCTalkOP.HAIR) { //更换发型出现
        slea.skip(2); //[00 00]
    }
    byte action = slea.readByte(); // 00 = end chat/no/decline, 01 == next/yes/accept
    int selection = -1;
    switch (op) {
        case TEXT:
            if (action != 0) {
                String returnText = slea.readMapleAsciiString();
                if (player.isShowPacket()) {
                    //player.dropSpouseMessage(0x0A, "Npc对话 - lastMsg: " + lastMsg + " action: " + action + " Text: " + returnText);
                }
                if (c.getQM() != null) {
                    c.getQM().setGetText(returnText);
                    if (c.getQM().isStart()) {
                        QuestScriptManager.getInstance().startAction(c, action, lastMsg, -1);
                    } else {
                        QuestScriptManager.getInstance().endAction(c, action, lastMsg, -1);
                    }
                } else if (c.getIM() != null) {
                    c.getIM().setGetText(returnText);
                    ItemScriptManager.getInstance().action(c, action, lastMsg, -1);
                } else if (c.getCM() != null) {
                    c.getCM().setGetText(returnText);
                    NPCScriptManager.getInstance().action(c, action, lastMsg, -1);
                }
            }
            return;
        case MIXED_HAIR:
            if (action == 0)
                break;
            slea.skip(6);
            c.getPlayer().handleMixHairColor((byte) slea.readInt(), (byte) slea.readInt(), (byte) slea.readInt());
            return;
        default:
            if (slea.available() >= 4) {
                selection = slea.readInt();
            } else if (slea.available() > 0) {
                selection = slea.readByte();
            }
            if (player.isShowPacket()) {
                //player.dropSpouseMessage(0x14, "Npc对话 - lastMsg: " + lastMsg + " action: " + action + " selection: " + selection);
            }
    }

    if (selection >= -1 && action != -1) {
        if (c.getQM() != null) {
            if (c.getQM().isStart()) {
                QuestScriptManager.getInstance().startAction(c, action, lastMsg, selection);
            } else {
                QuestScriptManager.getInstance().endAction(c, action, lastMsg, selection);
            }
        } else if (c.getIM() != null) {
            ItemScriptManager.getInstance().action(c, action, lastMsg, selection);
        } else if (c.getCM() != null) {
            NPCScriptManager.getInstance().action(c, action, lastMsg, selection);
        }
    } else {
        if (c.getQM() != null) {
            c.getQM().dispose();
        } else if (c.getIM() != null) {
            c.getIM().dispose();
        } else if (c.getCM() != null) {
            c.getCM().dispose();
        }
    }
}



   public static void repairAll(MapleClient c) {
/* 697 */     int price = 0;

/* 699 */     MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
/* 700 */     Map<Equip, Integer> eqs = new HashMap<>();
/* 701 */     MapleInventoryType[] types = { MapleInventoryType.EQUIP, MapleInventoryType.EQUIPPED };
/* 702 */     for (MapleInventoryType type : types) {
/* 703 */       for (Item item : c.getPlayer().getInventory(type).newList()) {
/* 704 */         if (item instanceof Equip) {
/* 705 */           Equip eq = (Equip)item;
/* 706 */           if (eq.getDurability() >= 0) {
/* 707 */             Map<String, Integer> eqStats = ii.getItemBaseInfo(eq.getItemId());
/* 708 */             if (eqStats.containsKey("durability") && ((Integer)eqStats.get("durability")).intValue() > 0 && eq.getDurability() < ((Integer)eqStats.get("durability")).intValue()) {
/* 709 */               double rPercentage = 100.0D - Math.ceil(eq.getDurability() * 1000.0D / ((Integer)eqStats.get("durability")).intValue() * 10.0D);
/* 710 */               eqs.put(eq, eqStats.get("durability"));
/* 711 */               price += (int)Math.ceil(rPercentage * ii.getUnitPrice(eq.getItemId()) / ((ii.getReqLevel(eq.getItemId()) < 70) ? 100.0D : 1.0D));
             }
           }
         }
       }
     }
/* 717 */     if (eqs.size() <= 0 || c.getPlayer().getMeso() < price) {
       return;
     }
/* 720 */     c.getPlayer().gainMeso(-price, true);

/* 722 */     for (Map.Entry<Equip, Integer> eqqz : eqs.entrySet()) {
/* 723 */       Equip ez = eqqz.getKey();
/* 724 */       ez.setDurability(((Integer)eqqz.getValue()).intValue());
/* 725 */       c.getPlayer().forceUpdateItem(ez.copy());
     }
   }




   public static void repair(LittleEndianAccessor slea, MapleClient c) {
/* 733 */     if (slea.available() < 4L) {
       return;
     }
/* 736 */     int position = slea.readInt();
/* 737 */     MapleInventoryType type = (position < 0) ? MapleInventoryType.EQUIPPED : MapleInventoryType.EQUIP;
/* 738 */     Item item = c.getPlayer().getInventory(type).getItem((short)position);
/* 739 */     if (item == null) {
       return;
     }
/* 742 */     Equip eq = (Equip)item;
/* 743 */     MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
/* 744 */     Map<String, Integer> eqStats = ii.getItemBaseInfo(item.getItemId());
/* 745 */     if (eq.getDurability() < 0 || !eqStats.containsKey("durability") || ((Integer)eqStats.get("durability")).intValue() <= 0 || eq.getDurability() >= ((Integer)eqStats.get("durability")).intValue()) {
       return;
     }
/* 748 */     double rPercentage = 100.0D - Math.ceil(eq.getDurability() * 1000.0D / ((Integer)eqStats.get("durability")).intValue() * 10.0D);


/* 751 */     int price = (int)Math.ceil(rPercentage * ii.getUnitPrice(eq.getItemId()) / ((ii.getReqLevel(eq.getItemId()) < 70) ? 100.0D : 1.0D));

/* 753 */     if (c.getPlayer().getMeso() < price) {
       return;
     }
/* 756 */     c.getPlayer().gainMeso(-price, false);
/* 757 */     eq.setDurability(((Integer)eqStats.get("durability")).intValue());
/* 758 */     c.getPlayer().forceUpdateItem(eq.copy());
   }




   public static void UpdateQuest(LittleEndianAccessor slea, MapleClient c) {
/* 765 */     MapleQuest quest = MapleQuest.getInstance(slea.readShort());
/* 766 */     if (quest != null) {
/* 767 */       c.getPlayer().updateQuest(c.getPlayer().getQuest(quest), true);
     }
   }

   public static void UseItemQuest(LittleEndianAccessor slea, MapleClient c) {
/* 772 */     short slot = slea.readShort();
/* 773 */     int itemId = slea.readInt();
/* 774 */     Item item = c.getPlayer().getInventory(MapleInventoryType.ETC).getItem(slot);
/* 775 */     int qid = slea.readInt();
/* 776 */     MapleQuest quest = MapleQuest.getInstance(qid);
/* 777 */     MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
/* 778 */     Pair<Integer, Map<Integer, Integer>> questItemInfo = null;
/* 779 */     boolean found = false;
/* 780 */     for (Item i : c.getPlayer().getInventory(MapleInventoryType.ETC)) {
/* 781 */       if (i.getItemId() / 10000 == 422) {
/* 782 */         questItemInfo = ii.questItemInfo(i.getItemId());
/* 783 */         if (questItemInfo != null && ((Integer)questItemInfo.getLeft()).intValue() == qid && questItemInfo.getRight() != null && ((Map)questItemInfo.getRight()).containsKey(Integer.valueOf(itemId))) {
/* 784 */           found = true;
           break;
         }
       }
     }
/* 789 */     if (quest != null && found && item != null && item.getQuantity() > 0 && item.getItemId() == itemId) {
/* 790 */       int newData = slea.readInt();
/* 791 */       MapleQuestStatus stats = c.getPlayer().getQuestNoAdd(quest);
/* 792 */       if (stats != null && stats.getStatus() == 1) {
/* 793 */         stats.setCustomData(String.valueOf(newData));
/* 794 */         c.getPlayer().updateQuest(stats, true);
/* 795 */         MapleInventoryManipulator.removeFromSlot(c, MapleInventoryType.ETC, slot, ((Integer)((Map)questItemInfo.getRight()).get(Integer.valueOf(item.getItemId()))).shortValue(), false);
       }
     }
   }

   public static void RPSGame(LittleEndianAccessor slea, MapleClient c) {
/* 801 */     if (slea.available() == 0L || c.getPlayer() == null || c.getPlayer().getMap() == null || !c.getPlayer().getMap().containsNPC(9000019)) {
/* 802 */       if (c.getPlayer() != null && c.getPlayer().getRPS() != null) {
/* 803 */         c.getPlayer().getRPS().dispose(c);
       }
       return;
     }
/* 807 */     byte mode = slea.readByte();
/* 808 */     switch (mode) {
       case 0:
       case 5:
/* 811 */         if (c.getPlayer().getRPS() != null) {
/* 812 */           c.getPlayer().getRPS().reward(c);
         }
/* 814 */         if (c.getPlayer().getMeso() >= 1000L) {
/* 815 */           c.getPlayer().setRPS(new RockPaperScissors(c, mode)); break;
         }
/* 817 */         c.announce(MaplePacketCreator.getRPSMode((byte)8, -1, -1, -1));
         break;

       case 1:
/* 821 */         if (c.getPlayer().getRPS() == null || !c.getPlayer().getRPS().answer(c, slea.readByte())) {
/* 822 */           c.announce(MaplePacketCreator.getRPSMode((byte)13, -1, -1, -1));
         }
         break;
       case 2:
/* 826 */         if (c.getPlayer().getRPS() == null || !c.getPlayer().getRPS().timeOut(c)) {
/* 827 */           c.announce(MaplePacketCreator.getRPSMode((byte)13, -1, -1, -1));
         }
         break;
       case 3:
/* 831 */         if (c.getPlayer().getRPS() == null || !c.getPlayer().getRPS().nextRound(c)) {
/* 832 */           c.announce(MaplePacketCreator.getRPSMode((byte)13, -1, -1, -1));
         }
         break;
       case 4:
/* 836 */         if (c.getPlayer().getRPS() != null) {
/* 837 */           c.getPlayer().getRPS().dispose(c); break;
         }
/* 839 */         c.announce(MaplePacketCreator.getRPSMode((byte)13, -1, -1, -1));
         break;
     }
   }






   public static void OpenQuickMoveNpc(LittleEndianAccessor slea, MapleClient c) {
/* 850 */     int npcid = slea.readInt();
/* 851 */     if (c.getPlayer().hasBlockedInventory() || c.getPlayer().isInBlockedMap() || c.getPlayer().getLevel() < 10) {
/* 852 */       c.getPlayer().dropMessage(-1, "您当前已经和1个NPC对话了. 如果不是请输入 @ea 命令进行解卡。");
       return;
     }
/* 855 */     for (MapleQuickMove pn : MapleQuickMove.values()) {
/* 856 */       if (pn.getNpcId() == npcid) {
/* 857 */         NPCScriptManager.getInstance().start(c, npcid);
         break;
       }
     }
   }
 }


/* Location:              C:\PGX\Server.jar!\handling\channel\handler\NPCHandler.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */